app.controller('search', function ($scope, $http) {
    $scope.keyWord=sessionStorage.getItem('keyWord');
    $scope.dataInfo=[];
    $.showPreloader('请稍候');
    $scope.searchClass=function(page){

        $scope.page = page ? page : 1;

        // 若该加载为初始化加载，即没有传入page参数
        if (!page) {
            $scope.page = 1;
        }

        $http({
            method: 'GET',
            url: app.netPath + '/class/keyword',
            params: {
                'keyWord': $scope.keyWord,
                'page': $scope.page
            }
        }).then(function(res){
            console.log(res.data);
            if(!res.data.error){
        //var dataInfo=res.data.data;
                $.hidePreloader();
                for(var i=0;i<res.data.data.length;i++){
                    res.data.data[i].classImg=app.netPath+'/resources/classImg/'+res.data.data[i].classImg;
                    app.buildImageUrl(res.data.data[i],'classImg',function () {
                        $scope.$digest();
                    });
                    $scope.dataInfo.push(res.data.data[i])

                }

                $scope.isOnloading = false;
                console.log($scope.dynamicInfos);


                //当前页
                $scope.thispage = $scope.dataInfo.length % 10 == 0 ? $scope.dataInfo.length / 10 : $scope.dataInfo.length / 10 + 1;
                $scope.thispage=parseInt($scope.thispage);
                var infiniteScroll = $('.infinite-scroll');
                var infiniteScrollPreloader = $('.infinite-scroll-preloader');
                // 启用无限加载事件
                $.attachInfiniteScroll(infiniteScroll);


                console.log($scope.thispage);
                if (res.data.allPage <= $scope.thispage) {
                    // 加载完毕，则注销无限加载事件，以防不必要的加载
                    $.detachInfiniteScroll(infiniteScroll);
                    // 删除加载提示符
                    infiniteScrollPreloader.hide();
                    $.hidePreloader()
                }
            $.hidePreloader()
            }
            if(res.data.error){
                $.hidePreloader()

            }
        },function(){
            $.hidePreloader()
            $.toast('网络走丢了！')
        })
    };

    $scope.search2=function(){
        sessionStorage.setItem('keyWord',$scope.keyWord);
        location.href='#search'
    };

    $scope.getClassId = function (classId) {
        sessionStorage.setItem('classId', classId);
        location.href = '#xiangqing';
    };
});